//
//  PhotoCollectionViewCell.m
//  WuliHanhan
//
//  Created by chen tang on 16/3/3.
//  Copyright © 2016年 LVpeng. All rights reserved.
//

#import "PhotoCollectionViewCell.h"

@interface PhotoCollectionViewCell ()
{
    UIImageView *photoImageView;
    UIButton *selectButton;
    
    
}
@end


@implementation PhotoCollectionViewCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initUI];
    }
    return self;
}


- (void)initUI
{
    [self setBackgroundColor:[UIColor yellowColor]];
    photoImageView = [[UIImageView alloc] initWithFrame:self.bounds];
    [self addSubview:photoImageView];
    
    
    UIImage *image = [UIImage imageNamed:@"weixuanze.png"];
    
    _selectImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.bounds.size.width-3-image.size.width, self.bounds.size.height-3-image.size.height, image.size.width, image.size.height)];
    [_selectImage setUserInteractionEnabled:YES];
    [self addSubview:_selectImage];

    
    selectButton = [[UIButton alloc] initWithFrame:self.bounds];
    [self addSubview:selectButton];
    [selectButton addTarget:self action:@selector(selectImage:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
}


//设置图片
- (void)setDataImage:(UIImage *)dataImage
{
    [photoImageView setImage:dataImage];
}



//选择图片
- (void)selectImage:(UIButton *)sender
{
    if ([selectButton isSelected])
    {
        //取消选中
        [_selectImage setImage:[UIImage imageNamed:@"weixuanze.png"]];

        [selectButton setSelected:NO];
    }
    else
    {
        //选中图片
        [_selectImage setImage:[UIImage imageNamed:@"Arrow.png"]];

        [selectButton setSelected:YES];
    }
    
//    NSLog(@"%d", self.tag);
    if (_MPhotoCollectionViewCellDelegate && [_MPhotoCollectionViewCellDelegate respondsToSelector:@selector(chooseImageWithIndex:withSelectBool:)])
    {
        [_MPhotoCollectionViewCellDelegate chooseImageWithIndex:self.tag withSelectBool:[selectButton isSelected]];
    }
    
}




//加载数据
- (void)setModelWith:(NSArray *)array;
{
    
    if ([array containsObject:[NSString stringWithFormat:@"%d", (int)self.tag]])
    {
        [_selectImage setImage:[UIImage imageNamed:@"Arrow.png"]];
        [selectButton setSelected:YES];

    }
    else
    {
        [_selectImage setImage:[UIImage imageNamed:@"weixuanze.png"]];
        [selectButton setSelected:NO];

    }
    
}




@end
